<?php
namespace app\helpers;

use yii\web\BadRequestHttpException;
use app\models\User;

class Request
{
    /**
     * 严格post
     * @param $name
     * @param $msg
     * @param null $default
     * @return array|mixed
     * @throws BadRequestHttpException
     */
    public static function strictpost($name,$msg,$default = null)
    {
        $value = \Yii::$app->request->post($name,$default);
        if($value===null){
            file_put_contents('aaa.txt',$msg,FILE_APPEND);
            throw new BadRequestHttpException($msg);
        }
        return $value;
    }

    /**
     * 宽松post
     * @param $name
     * @param null $default
     * @return array|mixed|null
     */
    public static function lowerpost($name,$default = null)
    {
        $value = \Yii::$app->request->post($name);
        if(!$value)
            return $default;
        return $value;
    }
    /**
     * 获取手机类型
     * @return int
     */
    public static function getPhoneType()
    {
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
            return User::PHONE_TYPE_IOS;
        }else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
            return User::PHONE_TYPE_ANDROID;
        }else{
            return User::PHONE_TYPE_LEAVE;
        }
    }
}